﻿using UnityEngine;
using System.Collections;

public class MenuGUIElements : MonoBehaviour {

    // TODO: Configure this value as levels are added or changed.
    // May also be based on purchases?
    public int numberOfGameLevels = 100;

    public enum MenuState
    {
        Main,
        Levels,
        Shop,
        Options
    }

    private MenuState currentMenuState = MenuState.Main;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    void OnGUI()
    {
        switch (currentMenuState)
        {
            case MenuState.Main:
                DoMainMenuGUI();
                break;
            case MenuState.Levels:
                DoLevelsGUI();
                break;
            case MenuState.Shop:
                DoShopGUI();
                break;
            case MenuState.Options:
                DoOptionsGUI();
                break;
        }


    }

    private void DoOptionsGUI()
    {
        // TODO: Create some options, even if it's just sound/volume/etc.
    }

    private void DoShopGUI()
    {
        throw new System.NotImplementedException();
    }

    private Vector2 levelScrollPosition = Vector2.zero;

    private void DoLevelsGUI()
    {
        levelScrollPosition = GUILayout.BeginScrollView(levelScrollPosition);
        for (int i = 0; i < numberOfGameLevels; i++)
        {
            if (GUILayout.Button(i.ToString()))
            {
                Application.LoadLevel(i + 2);
            }
        }
        GUILayout.EndScrollView();

        if (GUILayout.Button("Back"))
        {
            currentMenuState = MenuState.Main;
        }
    }

    private void DoMainMenuGUI()
    {
        if (GUILayout.Button("Start Game"))
        {
            // TODO: Integrate with userprefs to find which level to load
            Application.LoadLevel(2);
        }

        if (GUILayout.Button("Levels"))
        {
            print("Levels claimed is " + numberOfGameLevels);
            currentMenuState = MenuState.Levels;
        }

        if (GUILayout.Button("Rate Us"))
        {
            // TODO: Link to the rate system
        }

        if (GUILayout.Button("Shop"))
        {
            currentMenuState = MenuState.Shop;
        }

        if (GUILayout.Button("Options"))
        {
            currentMenuState = MenuState.Options;
        }
    }
}
